﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Datos.EntityFramework;
using Entidad;

namespace Datos.DAO
{
    public class HospedajeDAO
    {

          BD_HOTEL_Entities bd = new BD_HOTEL_Entities();
        public List<SRH_RESERVA> listarHospedaje()
        {

            List<SRH_RESERVA> lista = new List<SRH_RESERVA>();
            try
            {
                var q = from c in bd.SRH_RESERVA
                        select c;
                lista = q.ToList();

            }
            catch (Exception)
            {
            }
            return lista;
        }

        public bool Insertar(SRH_RESERVA Obj)
        {
            try
            {
                bd.AddObject("SRH_RESERVA", Obj);
                bd.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        public bool Modificar(SRH_RESERVA obj)
        {
            try
            {
                bd.AttachTo("SRH_RESERVA", obj);
                bd.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                bd.SaveChanges();
            }
            catch (Exception)
            {
                throw;
                            }
            return true;
        }

        public bool Eliminar(SRH_RESERVA obj)
        {
            try
            {
                bd.AttachTo("SRH_RESERVA", obj);
                bd.DeleteObject(obj);
                bd.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
            return true;
        }

        public int ObtenerNroHospedaje()
        {
            int id_opcion = 0;
  
            try
            {
                var q = (from c in bd.SRH_RESERVA
                         select c.idReserva).DefaultIfEmpty().Max();

                if (q == 0)
                {
                    id_opcion = 100;
                }
                else
                {
                    id_opcion = Convert.ToInt32(q) + 1;
                }
             
            }
            catch (Exception ex)
            {
                throw;
            }

            return id_opcion;
        }
     
        public static string Right(string param, int length)
        {

            int value = param.Length - length;
            string result = param.Substring(value, length);
            return result;
        }
    
    }
}
